package com.leetcode.tree.recursion;

import com.leetcode.basic.TreeNode;

/**
 * @author Dennis Li
 * @date 2020/6/15 16:41
 */
public class InvertTree_226 {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        TreeNode node = new TreeNode(root.val);
        // 核心是通过递归方法，将以前的右子树，赋值给新的左子树
        node.left = invertTree(root.right);
        node.right = invertTree(root.left);
        return node;
    }
}
